#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>


int searchInsert(int* nums, int numsSize, int target) {
    int tem = 0;
    int left = 0;
    int right = numsSize - 1;
    while (left < right)
    {
        tem = left + right / 2;
        if (nums[tem] > target)
        {
            if (tem != right)
            {
                right = tem;
            }
            else
                break;
        }
        else if (nums[tem] < target)
        {
            if (tem != left)
            {
                left = tem;
            }
            else
                break;
        }
        if (nums[tem] == target)
            return tem;
        if ((right - left) / 2 < 1 && target > nums[left] && target < nums[right])
            return left + 1;
    }
    if (target <= nums[0])
        return 0;
    else if (target == nums[numsSize - 1])
        return numsSize - 1;
    else
        return numsSize;


}
int main()
{
    int nums[] = { 1,3 };
    int tem = searchInsert(nums, 2, 3);
    printf("%d", tem);
}